const testUser = `auth_date=1753850908&hash=a02adc4bdbf63c90742ddbf7c48dc4836701c2d8f2a3eda3b09f05d8f4d9c6b9&signature=&start_param=&user=%7B%22added_to_attachment_menu%22%3Afalse%2C%22allows_write_to_pm%22%3Afalse%2C%22first_name%22%3A%223631315600%22%2C%22id%22%3A3631315600%2C%22is_bot%22%3Afalse%2C%22is_premium%22%3Afalse%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22%40i59irjd3%3Amt.social%22%2C%22language_code%22%3A%22zh-CN%22%2C%22photo_url%22%3A%22https%3A%2F%2Fmt.social%2F_matrix%2Fmedia%2Fv3%2Fthumbnail%2Fmt.social%2FKeDEZmaefnwODncPatfcpOcX%3Fwidth%3D384%26height%3D384%26method%3Dcrop%26allow_redirect%3Dtrue%22%2C%22provider%22%3A%22matrix%22%2C%22extra%22%3A%7B%22hs%22%3A%22mt.social%22%7D%7D`;

export default {
  actions: {
    async mpLogin({ dispatch }) {
      let initData = window.tgApp?.initData;
      if (uni.$h.inDev) {
        initData = testUser;
      }
      if (!initData) {
        return;
      }
      const { data } = await uni.$api.post("/bot/check-user", {
        initData,
      });
      dispatch("setStore", {
        userInfo: data.user,
        usrData: {
          token: data.token,
        },
      });
    },
    async getUserInfo({ dispatch }) {
      const { data } = await uni.$api.get("/bot/auth/user-info");
      return dispatch("setStore", {
        userInfo: data.user,
      });
    },
    async postUserInfo({ dispatch }, body) {
      const { data } = await uni.$api.post("/bot/auth/user-info", body);
      await dispatch("setStore", {
        userInfo: data,
      });
      return user;
    },
  },
};
